package com.findme.unvelouse.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.findme.unvelouse.R;
import com.findme.unvelouse.R.id;
import com.findme.unvelouse.R.layout;
import com.findme.unvelouse.bo.Favori;

public class FavoriAdapter extends BaseAdapter {

	List<Favori> mFavoriList = new ArrayList<Favori>();

	Context context;

	LayoutInflater inflater;

	private class ViewHolder {
		TextView tvStationName;
		TextView tvNbDispo;
		TextView tvNbTotal;
	}

	public FavoriAdapter(List<Favori> mFavoriList, Context context) {
		super();
		this.mFavoriList = mFavoriList;
		this.context = context;

		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return mFavoriList.size();
	}

	@Override
	public Object getItem(int position) {
		return mFavoriList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return mFavoriList.get(position).getNoStation();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder;

		if (convertView == null) {

			holder = new ViewHolder();

			convertView = inflater.inflate(R.layout.favori_row, null);

			holder.tvStationName = (TextView) convertView.findViewById(R.id.stationName);
			holder.tvNbDispo = (TextView) convertView.findViewById(R.id.nbDispo);
			holder.tvNbTotal = (TextView) convertView.findViewById(R.id.nbTotal);

			convertView.setTag(holder);

		} else {

			holder = (ViewHolder) convertView.getTag();

		}

		holder.tvStationName.setText(mFavoriList.get(position).getStationName());
		holder.tvNbDispo.setText(mFavoriList.get(position).getNbDispo().toString());
		holder.tvNbTotal.setText(mFavoriList.get(position).getNbPlace().toString());

		return convertView;

	}
}